package com.igeek.boot.controller;


import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeek.boot.entity.ContractTemplates;
import com.igeek.boot.entity.Warehouses;
import com.igeek.boot.result.Result;
import com.igeek.boot.service.IContractTemplatesService;
import com.igeek.boot.utils.QiniuUtils;
import com.igeek.boot.vo.PageQueryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jwj
 * @since 2023-12-26
 */
@RestController
@RequestMapping("/wisdom_factory/contract_templates")
@Api(tags = "模版表接口")
public class ContractTemplatesController {

    @Autowired
    private IContractTemplatesService templatesService;

    @GetMapping("/findPage")
    @ApiOperation("条件分页查询合同模版")
    public Result findPage(@ApiParam("分页条件") PageQueryVO pageQueryVO){
        Page<ContractTemplates> page = templatesService.findPage(pageQueryVO);
        if(!ObjectUtils.isEmpty(page)) return new Result(true,"分页合同模版查询成功",page);
        return new Result(false,"分页合同模版查询失败");
    }

    @PostMapping("/upload")
    @ApiOperation("上传合同模版")
    public Result upLoad(MultipartFile file) throws IOException {
        String fileName = templatesService.upload(file);
        if(StringUtils.hasLength(fileName)){
            return new Result(true,"上传成功",fileName);
        }
        return new Result(false,"上传失败");
    }

    @PostMapping("/addTemplates")
    @ApiOperation("上传合同模版信息")
    public Result addTemplates(@RequestBody ContractTemplates templates){
        boolean flag = templatesService.addTemplates(templates);
        if(flag){
            return new Result(true,"上传成功");
        }
        return new Result(false,"上传失败");
    }

//    @PostMapping("/wordToHtml")
//    @ApiOperation("上传合同模版信息")
//    public Result wordToHtml(@RequestBody WordVO wordVO){
//        boolean flag = templatesService.wordToHtml(wordVO);
//        if(flag){
//            return new Result(true,"上传成功");
//        }
//        return new Result(false,"上传失败");
//    }
}
